<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class GoodsController extends Controller
{

	//办公列表显示
	public function getIndex(Request $request)
	{
		if($request['name']){
			$goods = DB::table('Goods')
			->where('GoodsName','like','%'.$request['name'].'%')
			->paginate(10);
		}else{
			$goods = DB::table('Goods')
			->paginate(3);
		}
		 $info = $request -> all();
		return view('Lzk.Goods.Goods',['goods'=>$goods,'info'=>$info]);
	}

	//添加
	public function getAdd()
	{
		return view('Lzk.Goods.AddGoods');
	}

	//执行添加
	public function postInsert(Request $request)
	{
		// dd($request->all());
		$date = $request->only('GoodsId','GoodsClass','GoodsName','GoodsPrice','GoodsNumber');
		// dd($date);
		$res = DB::table('goods')->insert($date);
		if($res){
			return redirect('/Lzk/Goods');
		}else{
			return back();
		}
	}

	//编辑
	public function getEdit($id)
	{
		$ids = DB::table('goods')->where('id',$id)->first();
		// dd($ids);
		return view('Lzk.Goods.EditGoods',['ids'=>$ids]);
	}

	//执行修改
	public function postUpdate(Request $request)
	{
		// dd($request->all());
		
		$id = $request->only('id');
		$update = $request->only('GoodsId','GoodsClass','GoodsName','GoodsPrice','GoodsNumber');
		$edit = DB::table('goods')->where('id',$id)->update($update);
		if($edit){
					return redirect('/Lzk/Goods');
				}else{
					return back();
				}
	}

	//删除
	public function getDel($id)
	{
		$del = DB::table('Goods')->delete($id);
		if($del){
			return redirect('/Lzk/Goods');
		}else{
			return back();
		}
	}

	
}
